<%--
    Document   : search
    Author     : Nina
--%>
<%@ page import="webapp.model.Restaurant" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="webapp.model.User" %>
<%@ page import="webapp.model.UserManager" %>

<%
    Restaurant[] search_results = (Restaurant[]) request.getAttribute("search_results");
    int count = search_results.length;
    int height = 210;
    if(count > 2)
        height = 190;
    System.out.println(request.getAttribute("next_page"));
    int current = (Integer) request.getAttribute("show_page");
    boolean next = (Boolean) request.getAttribute("next_page");
    boolean prev = (Boolean) request.getAttribute("prev_page");
%>
<%@include file="/includes/header.jsp" %>
<link href="includes/css/recipelist.css" rel="stylesheet" type="text/css">
<div id="body" style="height:<%=(count * height) %>px">
    <%@include file="/includes/menu.jsp" %>
    <div id="right">
        <ul id="search">
        <% UserManager mgr = new UserManager();
        for(Restaurant r:  search_results){
                String image_path = r.getImage_url();
                if(image_path == null)
                    image_path = Integer.toString(r.getId()) + ".jpeg";

                String rate = "";
                rate = r.getRating();
                
                String hours = r.getOpenHours();
                String price = r.getPriceRange();
                String website = r.getWebsite();
                String address = r.getAddress();
    %>
                <li id="recipe_<%=r.getId() %>" >
                    <img width="140" height="140" title="<%=r.getName()%>" src="restaurants/<%=image_path %>"/>
                    <p class="title"><a href="viewrestaurant?restaurant_id=<%=r.getId() %>"><%=r.getName()%></a></p>
                    <p class="rating">Rating: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=rate %>/5.0</p>
                    <p class="hours">Hours: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=hours %></p>
                    <p class="price">Price Range: &nbsp;<%=price %></p>
                    <p class="website">Website: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=website %></p>
                    <p class="address">Address: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=address %></p>
                </li>
        <% 
        }%>
        </ul>
        <div id="pagination">
            <%if(prev){%>
	            <a title="Prev" id="prev" href="search?Type=<%=type%>&Price=<%=pricing%>&Ratig=<%=rating%>&keyword=<%=keyword%>&show_page=<%=(current-1)%>"><span>&lt;&lt; Prev</span></a>
            <%}%>
            <a id="current" href="">&nbsp;<%=(current + 1)%>&nbsp;</a>
            <%if(next){%>
	            <a title="Prev" id="prev" href="search?Type=<%=type%>&Price=<%=pricing%>&Ratig=<%=rating%>&keyword=<%=keyword%>&show_page=<%=(current+1)%>"><span>Next &gt;&gt;</span></a>
            <%}%>
        </div>
    </div>
</div>

<%@include file="/includes/footer.jsp" %>